def replace_block_no_reg(file_path, original_block_head):
	# 临时文件路径，用于存储处理后的内容
	lines_to_keep = []
	# 标记是否开始删除块内容
	start_check = False
	ignore_in_block = False
	nest = 0
	stop_check = False
	# 读取原文件并写入临时文件，跳过需要删除的块
	with open(file_path, 'r', encoding='utf-8') as read_file:
		for line in read_file:
			# 检查是否开始新的块，如果是则开始忽略内容
			if line.strip() == original_block_head + " = {":
				start_check = True
				continue  # 跳过当前行不写入
			# 当前行以'}'开始，表示结束标记，重置flag并继续处理下一行
			if '{' in line and start_check:
				nest += 1
			if '}' in line and start_check:
				nest -= 1
			if '}' in line and start_check and nest < 0:
				start_check = False
				continue
			# 如果不在删除范围内，则写入该行
			if not start_check:
				lines_to_keep.append(line)
	# print(lines_to_keep)

	with open(file_path, 'w', encoding='utf-8') as write_file:
		write_file.writelines(lines_to_keep)
		
block_head = "building_gold_mine"
file_path = "/mnt/games/Victoria 3/game/common/buildings/03_mines.txt"
replace_block_no_reg(file_path, block_head)